<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class School_model extends CI_Model {
	public function __construct() {
		parent::__construct ();
	}
	/*
	 * 返回学校信息
	 */
	public function get_schools(){
		$query = $this->db->get('t_school');
		return $query->result_array();
	}
	/*
	 *根据学校类型返回年级
	 */
	public function find_grade_by_type($type){
		$this->db->where('type', $type);
		$query = $this->db->get('t_grade');
		return $query->result_array();
	}
	/*
	 *根据学校年级返回班级
	 */
	public function find_class_by_school_grade($school,$grade){
		$this->db->where('schoolid', $school);
		$this->db->where('gradeid', $grade);
		$query = $this->db->get('t_class');
		return $query->result_array();
	}
	/*
	 *根据班级ID返回班级信息
	 */
	public function find_class_by_id($id){
		$this->db->select('t_class.id,t_class.schoolid,t_class.gradeid,t_school.type');
		$this->db->from('t_class');
		$this->db->join('t_school', 't_class.schoolid = t_school.id','left');
		$this->db->where("t_class.id", $id);
		$query = $this->db->get();
		return  $query->row_array();
	}
}
